import { EventTypes, OrderTypes } from "../pages/pagesTypes";
import {
  ApiItemTypeMapping,
  ItemListingCardShape,
} from "../shared/entityShapes";
import { ImageStringFormat } from "../shared/mediaTypes";
import { DateShape, TimeShape } from "../shared/timeTypes";
import { ShopItemTypes } from "../shop/shopTypes";

export interface CartItemShape {
  id: number;
  name: string;
  imagePath: string;
  itemType: ShopItemTypes;
  tag: "default" | Omit<string, "default">;
  tagColor: string;
  quantity: number;
  unitPrice: number;
  availability: number;
  categoryName: string;
  productId: number;
  attrStatus: boolean;
}

export type Titles = "先生" | "女士";

export type AddressFieldShape = {
  id?: number | null;
  title?: Titles | null;
  residenceArea: string[];
  address: string;
  name: string;
  phone: string;
  isPrimary: boolean;
};

export type OrderHistoryStoreItemShape = {
  orderDate: `${string}-${string}-${string}  ${string}:${string}:${string}`;
  deliveryStatus: "待收货" | "已收货";
  orderNumber: number;
  thumbNails: ImageStringFormat[];
  totalItemsOrdered: number;
  orderTotalPrice: number;
};

// Subset not including 4 = ShopItem
export type ApiEventOnlyMapping = Exclude<
  ApiItemTypeMapping,
  ApiItemTypeMapping.ShopItem
>;

export type GiftPayloadShape = {
  name: string;
  orderInfoIds: number[];
  appointmentSchedulings: {
    name: string;
    schedulingDate: DateShape;
    schedulingStartTime: TimeShape;
    schedulingEndTime: TimeShape;
  }[];
  type: ApiEventOnlyMapping;
};

export type LineUpPayloadShape = {
  mainId: number; // ID for event
  mainType: ApiEventOnlyMapping;
  name: string;
  lineUpId: number; // Used to call "Do not show anymore API"
  // noticeStatus: number; // Is needed? If yes => create enum
}[];

export type UserInfoShape = {
  uid: number;
  title: Titles | null;
  nickName: string;
  fullName: string;
  phoneNumber: string;
  email: string;
  residenceArea: string[];
  birthDay: DateShape | string;
  collectionCount: number;
  coursesCount: number;
  giftCardsCount: number;
  exhibitionsCount: number;
  shoppingCartsCount: number;
  talkCount: number;
  noGetAppoinment: GiftPayloadShape[];
  lineUpResponses: LineUpPayloadShape;
  userQrCode: string;
  defaultAddress: AddressFieldShape;
  deliveryAddress: AddressFieldShape[];
};

export type GiftCertificateShape = {
  name: string;
  id: number;
  title: string;
  startTime?: DateShape;
  endTime: DateShape;
  usedTime?: DateShape;
  mainColor: string;
  secondaryColor: string;
  tertiaryColor: string;
  status?: number;
  cardId?: number;
  cardNo?: string;
  faceValue?: string;
};

export type UserShape = {
  userInfo: UserInfoShape;
  cart: CartItemShape[];
  giftCertificates: GiftCertificateShape[];
  likedItems: Array<
    ItemListingCardShape & { eventType: EventTypes; available: boolean }
  >;
  // User courses/talks/exhibitions (excluding cancelled and similar -> listed in transaction history)
  userEvents: {
    [key in EventTypes]: {
      past: ItemListingCardShape[];
      upcoming: ItemListingCardShape[];
    };
  };
  // Order history temp here -> likely will be split into separate APIs as likely quite heavy...
  orderHistory: {
    [OrderTypes.Events]: ItemListingCardShape[]; // ID in this case assumed to be order-ID
    [OrderTypes.StoreItems]: OrderHistoryStoreItemShape[];
  };
  waitingList: Array<
    ItemListingCardShape & {
      eventType: EventTypes;
      available: boolean;
    }
  >;
};

export type UserPageShape = {
  topBackgroundImage: string;
  centerBackgroundImage: string;
};
